package com.hfkh.keyun.controller.frontend;
import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.Evaluate;
import com.hfkh.keyun.exception.BusinessException;
import com.hfkh.keyun.service.EvaluateService;
import com.hfkh.keyun.vo.EvaluateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("/api/evaluate")
@Api(tags = "评论管理")
public class EvaluateControllerApp {
    @Resource
    private EvaluateService evaluateService;
    /**
     * 查询所有评论
     * @return
     */
    @ApiOperation("查询全部评论")
    @GetMapping("/selectEvaluate")
    public List<Evaluate> queryAllEvaluate(){
        List<Evaluate> evaluate = evaluateService.list(null);
        evaluate.forEach(System.out::println);
        return evaluate;
    }
    /**
     * 根据id删除评论
     * @param id
     */
    @ApiOperation("根据id删除评论")
    @DeleteMapping("/delEvaluate")
    public void deleteById(Integer id){
        evaluateService.removeById(id);
    }
    /**
     * 增加评论
     */
    @ApiOperation("增加评论")
    @PostMapping("/addEvaluate")
    public ApiResult addEvaluate(EvaluateVO evaluateVO) throws BusinessException, IOException {
        return evaluateService.addEvaluate(evaluateVO);
    }
}
